<?php
class spIDInfo{
    public $json;
    public $userinfo;
    
    private $sc;
    public function __construct() {
        $this->sc = spClass('SysCrypt');    //创建加密对象
        $this->sc->setkey($GLOBALS['GLOBALS']['spConfig']['ext']['spIDInfo']['key']);  //设置key值
    }
    public function write($arr) {   
        $this->json = $this->sc->php_encrypt(json_encode($arr));
        setcookie('user', $this->json); 
    }
    public function read() {
        if(isset($_COOKIE['user'])){
            $value = json_decode($this->sc->php_decrypt($_COOKIE['user']));
            if(isset($value->id)){
                $this->userinfo = $value;
                $this->json = $_COOKIE['user'];
                return TRUE;
            }else{
                return FALSE;
            }
        }else{
            return FALSE;
        }
    }
    public function readjson($json){
        if(isset($json)){
            $value = json_decode($this->sc->php_decrypt($json));
            if(isset($value->id)){
                $this->userinfo = $value;
                $this->json = $json;
                return TRUE;
            }else{
                print_r($this->sc->php_decrypt($json));
                return FALSE;
            }
        }else{
            echo '2';
            return FALSE;
        }
    }
    public function clear() {
        setcookie('user','',  time()-3600);
    }
}
?>